package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

import java.util.HashMap;
import java.util.Map;

class LongestPalindrome {
    // 2022-08-30 17:13:19
    public static void main(String[] args) {
        Solution solution = new LongestPalindrome().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int longestPalindrome(String s) {
            Map<Character, Integer> map = new HashMap<>();
            for (int i = 0; i < s.length(); i++) {
                map.put(s.charAt(i), map.getOrDefault(s.charAt(i), 0) + 1);
            }
            int ans = 0;
            int single = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                Integer v = entry.getValue();
                if (v % 2 == 0) {
                    ans += v;
                } else {
                    ans += v - 1;
                    single = 1;
                }
            }
            return ans + single;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}